package com.ybkj.o2o.zhuanche.manager.impl;

import com.ybkj.o2o.zhuanche.common.DataGrid;
import com.ybkj.o2o.zhuanche.entity.Order;
import com.ybkj.o2o.zhuanche.entity.PassengerComplaints;
import com.ybkj.o2o.zhuanche.manager.PassengerComplaintsManager;
import com.ybkj.o2o.zhuanche.service.OrderService;
import com.ybkj.o2o.zhuanche.service.PassengerComplaintsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Administrator on 2017/3/8.
 */
@Service
public class DefaultPassengerComplaintsManager implements PassengerComplaintsManager {

  @Autowired
  private PassengerComplaintsService passengerComplaintsService;
  
  @Autowired
  private OrderService orderService;

  @Override
  public PassengerComplaints create(PassengerComplaints pc) {
    Order order = orderService.findByIdAndAppKey(pc.getOrderId(), pc.getAppKey());
    pc.setOrderNo(order.getOrderNo());
    int rows = passengerComplaintsService.save(pc);
    return pc;
  }

  @Override
  public DataGrid<PassengerComplaints> findByPage(Long orderId, String appKey, Integer page, Integer rows) {
    Integer offset = null;
    if(page != null && rows != null){
      offset = (page-1)*rows;
    }
    List<PassengerComplaints> list = passengerComplaintsService.selectByOrderId(orderId,appKey,offset,rows);
    long total = passengerComplaintsService.countByOrderId(orderId,appKey);
    DataGrid<PassengerComplaints> data = new DataGrid<>();
    data.setTotal(total);
    data.setRows(list);
    return data;
  }

  @Override
  public PassengerComplaints deleteById(Long pcId, String appKey) {
    PassengerComplaints one = passengerComplaintsService.findOne(pcId, appKey);
    int i = passengerComplaintsService.deleteById(pcId, appKey);
    return one;
  }
}
